import 'dart:async';
import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wanxiang_app/pages/index.dart';
import 'package:wanxiang_app/pages/login/login.dart';
import 'package:wanxiang_app/utils/common.dart';
import 'package:wanxiang_app/utils/constant.dart';
import 'package:wanxiang_app/utils/sp_util.dart';
import '../../bean/login_entity.dart';
import '../../bean/registe_entity.dart';
import '../../bean/simple_entity.dart';
import '../../utils/RegExpUtils.dart';
import '../../utils/encodeUtil.dart';
import '../../utils/network_manager.dart';
import '../../utils/network_url.dart';
import '../../utils/tabChangeEvent.dart';
import '../../utils/toast_util.dart';
import '../../utils/user_util.dart';
import '../../widgets/account_textField2.dart';
import '../../widgets/change_phone_dialog.dart';
import '../../widgets/myappbar.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';

import '../../widgets/simple_dialog.dart';
import 'package:nim_core/nim_core.dart';

import '../login/login_code.dart';
class ProfileController extends GetxController {
  @override
  void onInit() {
    super.onInit();
    _getService();
  }


  @override
  void onClose() {
    super.onClose();
    if(_timer!=null){
      _timer?.cancel();
    }
  }

  late LoginData data;
  bool isInital = false;

  void _getService() {
    DioManager.getInstance()
        .post(ServiceUrl.myInfo, {"user_name": UserUtil.getUSER()?.userName},
            (data1) async {
      LoginEntity entity = LoginEntity.fromJson(jsonDecode(data1));
      var map = jsonDecode(data1);
      data = entity.data;
      isInital = true;
      var map2 = map['data'];
      UserUtil.saveUSER2(jsonEncode(map2).toString());
      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }

  void _upload(base64Str) {
    DioManager.getInstance().post(ServiceUrl.modifyAvater, {
      "user_name": UserUtil.getUSER()?.userName,
      "img_src":base64Str,
    }, (data) async {
      SimpleEntity simpleEntity =   SimpleEntity.fromJson(jsonDecode(data));
      if(simpleEntity.code ==200){
        ToastUtil.show('修改成功');
        _getService();
      }
      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }

  String updateStr =  '';

   _updateUser(key) {
    Map map = {};

    // {
    //   "user_name": UserUtil.getUSER()?.userName,
    //  "nick_name":'',
    //  "telphone":'',
    //  "qq":'',
    //  'msn':''
    //  }
    //
    if(key=='QQ'){
      map = {
        "user_name": UserUtil.getUSER()?.userName,
        "qq":updateStr,
      };

    }
    if(key=='微信'){
      map = {
        "user_name": UserUtil.getUSER()?.userName,
        "msn":updateStr,
      };
    }
    if(key=='电话'){
      map = {
        "user_name": UserUtil.getUSER()?.userName,
        "telphone":updateStr,
      };
    }

    if(key=='昵称'){
      map = {
        "user_name": UserUtil.getUSER()?.userName,
        "nick_name":updateStr,
      };
    }

    DioManager.getInstance().post(ServiceUrl.updateUser, map, (data) async {
      SimpleEntity simpleEntity =   SimpleEntity.fromJson(jsonDecode(data));
      ToastUtil.show(simpleEntity.msg);
      if(simpleEntity.code ==200){
        _getService();
      }
      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }

  var timeTip = '获取验证码'.obs ;
   Timer? _timer;
  int countTime = 60;
  String code = '';
  String psw ='';
  String psw2 ='';
  void _countTime() {
    _timer = Timer.periodic(const Duration(milliseconds: 1000), (timer) {
      countTime--;
      if (countTime == 0) {
        _timer?.cancel();
        countTime = 60;
        timeTip.value = '重新获取' ;
      } else {
        timeTip.value = '重新获取${countTime}S';
      }
      print('  timeTip.value=='+  timeTip.value);
      update();
    });
  }

  String deleteCodeStr =  '';
  String deletePhoneStr =  '';
  _getCode(code_type) {
    if (countTime != 60) {
      return;
    }
    if (data.mobile.isEmpty || data.mobile.length < 11 || !RegExpUtils.isPhoneNumber(data.mobile)) {
      ToastUtil.show('请正确输入手机号');
      return;
    }
    DioManager.getInstance().post(
        ServiceUrl.loginCode, {'code_type': code_type, 'mobile': data.mobile.toString()},
            (data) async {
          _countTime();
          update();
        }, (error) {
      ToastUtil.show(error);
    });
  }

  _getCodeDelete(code_type) {
    if (countTime != 60) {
      return;
    }
    deletePhoneStr = UserUtil.getUSER()!.mobile;
    if (deletePhoneStr.isEmpty || deletePhoneStr.length < 11 || !RegExpUtils.isPhoneNumber(deletePhoneStr)) {
      ToastUtil.show('请正确输入手机号');
      return;
    }
    DioManager.getInstance().post(
        ServiceUrl.loginCode, {'code_type': code_type, 'mobile': deletePhoneStr.toString()},
            (data) async {
          _countTime();
          update();
        }, (error) {
      ToastUtil.show(error);
    });
  }

  _deleteUser(){
    DioManager.getInstance().post(ServiceUrl.deleteUser, {
      "user_name": data.mobile,
      'verifyCode':deleteCodeStr,
    }, (data) async {
      SimpleEntity bannerEntity = SimpleEntity.fromJson(jsonDecode(data));
      ToastUtil.show(bannerEntity.msg);
      if (bannerEntity.code == 200) {
        UserUtil.loginout();
        tabbarEventBus.fire(TabChangedEvent(-1));
        Get.offAll(()=>IndexPage());
      }else{

      }
    }, (error) {
      ToastUtil.show(error);
    });
  }


  void _submit() {
    if (data.mobile.isEmpty) {
      ToastUtil.show('请正确输入手机号');
      return;
    }

    if (code.isEmpty) {
      ToastUtil.show('请输入验证码');
      return;
    }

    if (psw.isEmpty ) {
      ToastUtil.show('请正确输入密码');
      return;
    }

    if (psw2.isEmpty ) {
      ToastUtil.show('请正确输入密码');
      return;
    }

    // if (psw2 != psw) {
    //   ToastUtil.show('两次密码不一致');
    //   return;
    // }

    DioManager.getInstance().post(ServiceUrl.changePSw, {
      "verifyCode": code,
      "password": psw2,
      "username": data.mobile,
    }, (data) async {
      RegisteEntity bannerEntity = RegisteEntity.fromJson(jsonDecode(data));
      ToastUtil.show(bannerEntity.msg);
      if (bannerEntity.code == 200) {
        ToastUtil.show("修改成功");
        if (_timer != null) {
          _timer?.cancel();
        }
        Get.back();
      }else{

      }
    }, (error) {
      ToastUtil.show(error);
    });
  }




}

class ProfilePage extends GetView<ProfileController> {
  late ProfileController controller;

  late BuildContext context;

  @override
  Widget build(BuildContext context1) {
    Get.lazyPut<ProfileController>(() => ProfileController());
    controller = Get.find();
    context = context1;

    return GetBuilder<ProfileController>(
      builder: (_) {
        return Scaffold(
          // resizeToAvoidBottomInset: false,
            appBar: MyAppBar(
              context: context,
              title: '个人资料',
              hasLeading: true,
            ),
            backgroundColor: Color(0xFFF7F8FC),
            body: SingleChildScrollView(
              child: _content()
            ) );
      },
    );
  }

  Widget _content() {
    return !controller.isInital?Container(): Container(
      padding: EdgeInsets.fromLTRB(16.w, 6.h, 16.w, 0),
      child: Column(
        children: [
          _item('img', '头像', ''),
          SizedBox(
            height: 6.h,
          ),
          Container(
            decoration: BoxDecoration(
                color: Colors.white, borderRadius: BorderRadius.circular(10.r)),
            child: Column(
              children: [
                SizedBox(
                  height: 1.h,
                ),
                _item2('input', '昵称', controller.data.nickname),
                _item2('choose', '手机号', controller.data.mobile),
                InkWell(
                  onTap: () {
                    _showPsw();
                  },
                  child: _item2('choose', '登录密码', '修改密码'),
                ),
                SizedBox(
                  height: 4.h,
                ),
              ],
            ),
          ),
          SizedBox(
            height: 6.h,
          ),
          Container(
            decoration: BoxDecoration(
                color: Colors.white, borderRadius: BorderRadius.circular(10.r)),
            child: Column(
              children: [
                SizedBox(
                  height: 1.h,
                ),
                _item2('input', '联系电话', controller.data.telphone),
                _item2('input', '联系微信',  controller.data.wechat),
                _item2('input', '联系QQ',  controller.data.qq),
                SizedBox(
                  height: 4.h,
                ),
              ],
            ),
          ),
          SizedBox(
            height: 6.h,
          ),
          _item('choose', '注销账号', ''),
          SizedBox(
            height: 6.h,
          ),
          InkWell(
              onTap: () {
                NimCore.instance.authService
                    .logout()
                    .then(
                        (result) {
                      if (result.isSuccess) {
                        tabbarEventBus.fire(TabChangedEvent(200));
                        /// 成功
                      } else {
                        /// 失败
                      }
                    }
                );
                Get.to(()=>LoginCodePage());
              },
              child: _item('choose', '退出登录', '')),
          // _logout()
        ],
      ),
    );
  }

  TextEditingController _controller = TextEditingController();

  Widget _item(type, key, value) {
    return InkWell(
      onTap: (){
        if(key=='注销账号'){
          _showDelte();
        }else if(key=='退出登录'){
          ToastUtil.show("您已退出了，欢迎下次再来哦。");
          Future.delayed(const Duration(milliseconds: 500), () {
            UserUtil.loginout();
            // SpUtil.clear();
            tabbarEventBus.fire(TabChangedEvent(-1));
            Get.offAll(()=>IndexPage());
          });
        }

      },
      child: Container(
        padding: EdgeInsets.only(left: 16.w, right: 16.w),
        height: 52.h,
        decoration: BoxDecoration(
            color: Colors.white, borderRadius: BorderRadius.circular(10.r)),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              key,
              style: TextStyle(color: Color(0xFF999999), fontSize: 13.sp),
            ),
            Row(
              children: [
                type == 'img'
                    ? InkWell(
                    onTap: () async{
                      final ImagePicker picker = ImagePicker();
                      final XFile? image = await picker.pickImage(source: ImageSource.gallery);
                      EncodeUtil.image2Base64(image!.path.toString()).then((data){
                        controller._upload(data);
                      });
                    },
                    child: ClipOval(
                      child: Image.network(
                        controller.data.userPhoto,
                        width: 33.w,
                        height: 33.w,
                        fit: BoxFit.cover,
                      )
                    )
                )
                    : (type == 'input'
                    ? Container(
                    width: 150.w,
                    child: TextField(
                      textAlign: TextAlign.end,
                      controller: _controller,
                      decoration: InputDecoration(
                        border: InputBorder.none,
                        hintText: value,
                      ),
                      onChanged: (e) {},
                    ))
                    : Text(
                  value,
                  style: TextStyle(
                      color: Color(0xFF333333), fontSize: 13.sp),
                )),
                SizedBox(
                  width: 13.w,
                ),
                type == 'input'
                    ? Container()
                    : Image.asset(
                  '${Constant.IMG_BASE}arrow_right.png',
                  width: 6.w,
                  height: 11.h,
                )
              ],
            )
          ],
        ),
      )
    ) ;
  }

  Widget _item2(type, key, value) {
    return InkWell(
      onTap: (){
        if(key=='联系电话'){
          _showSingle('电话');
        }else if(key=='联系微信'){
          _showSingle('微信');
        }else if(key=='联系QQ'){
          _showSingle('QQ');
        }else if(key=='昵称'){
          _showSingle('昵称');
        }else if(key=='登录密码'){
          _showPsw();
        }
      },
      child:  Container(
        padding: EdgeInsets.only(left: 16.w, right: 16.w),
        height: 52.h,
        decoration: BoxDecoration(
          color: Colors.white,
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              key,
              style: TextStyle(color: Color(0xFF999999), fontSize: 13.sp),
            ),
            Row(
              children: [
                type == 'img'
                    ? Image.asset(
                  '${Constant.IMG_BASE}avater.png',
                  width: 33.w,
                  height: 33.h,
                )
                    : (
                    Text(
                      value,
                      style: TextStyle(
                          color: Color(0xFF333333), fontSize: 13.sp),
                    )),
                SizedBox(width: 10.w,),
                Image.asset(
                  '${Constant.IMG_BASE}arrow_right.png',
                  width: 6.w,
                  height: 11.h,
                )
              ],
            )
          ],
        ),
      )
    );
  }

  Widget _logout() {
    return InkWell(
        onTap: () {
          // _showPhone();
          Get.back(result: -1);
        },
        child: Container(
          margin: EdgeInsets.only(top: 40.h,bottom: 40.h),
          height: 42.h,
          width: MediaQuery.of(context).size.width - 64.w,
          alignment: Alignment.center,
          decoration: BoxDecoration(
              color: Color(0xFF007BE5),
              borderRadius: BorderRadius.circular(22.r)),
          child: Text(
            '保存头像',
            style: TextStyle(fontSize: 14.sp, color: Colors.white),
          ),
        ));
  }

  Future<Future<int?>> _showPhone() async {
    return showModalBottomSheet<int>(
      backgroundColor: Colors.transparent,
      isScrollControlled: true,
      context: context,
      builder: (BuildContext context) {
        return Container(
          clipBehavior: Clip.antiAlias,
          decoration: const BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(20.0),
              topRight: Radius.circular(20.0),
            ),
          ),
          height: MediaQuery.of(context).size.height / 2.0,
          child: Column(children: [
            SizedBox(
              height: 50,
              child: Stack(
                textDirection: TextDirection.rtl,
                children: [
                  const Center(
                    child: Text(
                      '更换手机号',
                      style: TextStyle(
                        fontSize: 15,
                        color: Color(0xFF333333),
                      ),
                    ),
                  ),
                  IconButton(
                      icon: Icon(Icons.close),
                      onPressed: () {
                        Navigator.of(context).pop();
                      }),
                ],
              ),
            ),
            Expanded(
              child: Container(
                width: MediaQuery.of(context).size.width,
                alignment: Alignment.center,
                child: Column(
                  children: [
                    SizedBox(
                      height: 12.h,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          '原手机号：',
                          style: TextStyle(
                              color: Color(0xFF333333), fontSize: 14.sp),
                        ),
                        Container(
                          height: 38.h,
                          width: 230.w,
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(4.r),
                              border: Border.all(
                                  width: 1.w, color: Color(0xFFE4E4E4))),
                          child: AccountEdit2Text(
                            //获取返回的输入内容
                            hitText: '请输入',
                            icon: '',
                            contentStrCallBack: (content) {},
                            key: ValueKey('phone'),
                          ),
                        )
                      ],
                    ),
                    SizedBox(
                      height: 12.h,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          '新手机号：',
                          style: TextStyle(
                              color: Color(0xFF333333), fontSize: 14.sp),
                        ),
                        Container(
                          height: 38.h,
                          width: 230.w,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(4.r),
                              border: Border.all(
                                  width: 1.w, color: Color(0xFFE4E4E4))),
                          child: AccountEdit2Text(
                            //获取返回的输入内容
                            hitText: '请输入',
                            icon: '',
                            contentStrCallBack: (content) {},
                            key: ValueKey('newphone'),
                          ),
                        )
                      ],
                    ),
                    SizedBox(
                      height: 12.h,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        SizedBox(
                          width: 10.w,
                        ),
                        Text(
                          '验证码：',
                          style: TextStyle(
                              color: Color(0xFF333333), fontSize: 14.sp),
                        ),
                        SizedBox(
                          width: 5.w,
                        ),
                        Container(
                          height: 38.h,
                          width: 149.w,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(4.r),
                              border: Border.all(
                                  width: 1.w, color: Color(0xFFE4E4E4))),
                          child: AccountEdit2Text(
                            //获取返回的输入内容
                            hitText: '请输入',
                            icon: '',
                            contentStrCallBack: (content) {},
                            key: ValueKey('newphone'),
                          ),
                        ),

                        InkWell(
                          onTap: (){

                          },
                          child: Container(
                            margin: EdgeInsets.only(left: 10.w),
                            width: 74.w,
                            height: 38.h,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              color: Color(0xFF007BE5),
                              borderRadius: BorderRadius.circular(4.r),
                            ),
                            child: Text(
                              '获取验证码',
                              style:
                              TextStyle(color: Colors.white, fontSize: 11.sp),
                            ),
                          )
                        )

                     ,
                      ],
                    ),
                    InkWell(
                        onTap: () {},
                        child: Container(
                          margin: EdgeInsets.only(top: 40.h),
                          height: 42.h,
                          width: MediaQuery.of(context).size.width - 64.w,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              color: Color(0xFF007BE5),
                              borderRadius: BorderRadius.circular(8.r)),
                          child: Text(
                            '确定',
                            style:
                                TextStyle(fontSize: 14.sp, color: Colors.white),
                          ),
                        ))
                  ],
                ),
              ),
            ),
          ]),
        );
      },
    );
  }

  Future<Future<int?>> _showPsw() async {
    return showModalBottomSheet<int>(
      backgroundColor: Colors.transparent,
      isScrollControlled: true,
      context: context,
      builder: (BuildContext context) {
        return  AnimatedPadding(
            padding: MediaQuery.of(context).viewInsets, // 我们可以根据这个获取需要的padding
        duration: const Duration(milliseconds: 100),
        child: Container(
          clipBehavior: Clip.antiAlias,
          decoration: const BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(20.0),
              topRight: Radius.circular(20.0),
            ),
          ),
          height: MediaQuery.of(context).size.height / 2.0,
          child: Column(children: [
            SizedBox(
              height: 50,
              child: Stack(
                textDirection: TextDirection.rtl,
                children: [
                  const Center(
                    child: Text(
                      '登录密码',
                      style: TextStyle(
                        fontSize: 15,
                        color: Color(0xFF333333),
                      ),
                    ),
                  ),
                  IconButton(
                      icon: Icon(Icons.close),
                      onPressed: () {
                        if( controller._timer!=null){
                          controller._timer?.cancel();
                        }

                        Navigator.of(context).pop();
                      }),
                ],
              ),
            ),
            Expanded(
              child: Container(
                width: MediaQuery.of(context).size.width,
                alignment: Alignment.center,
                child: Column(
                  children: [
                    SizedBox(
                      height: 12.h,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          '手机号：',
                          style: TextStyle(
                              color: Color(0xFF333333), fontSize: 14.sp),
                        ),
                        Container(
                          height: 38.h,
                          width: 230.w,
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(4.r),
                              border: Border.all(
                                  width: 1.w, color: Color(0xFFE4E4E4))),
                          child: AccountEdit2Text(
                            //获取返回的输入内容
                            hitText: '请输入',
                            icon: '',
                            defaultText: controller.data.mobile,
                            contentStrCallBack: (content) {
                              controller.data.mobile = content;
                            },
                            key: ValueKey('phone'),
                          ),
                        )
                      ],
                    ),
                    SizedBox(
                      height: 12.h,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        SizedBox(
                          width: 5.w,
                        ),
                        Text(
                          '验证码：',
                          style: TextStyle(
                              color: Color(0xFF333333), fontSize: 14.sp),
                        ),
                        Container(
                          height: 38.h,
                          width: 149.w,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(4.r),
                              border: Border.all(
                                  width: 1.w, color: Color(0xFFE4E4E4))),
                          child: AccountEdit2Text(
                            //获取返回的输入内容
                            hitText: '请输入',
                            icon: '',
                            contentStrCallBack: (content) {
                              controller.code= content;
                            },
                            key: ValueKey('newphone'),
                          ),
                        ),

                        InkWell(
                          onTap: (){
                            controller._getCode('3');
                           // controller._countTime();
                          },
                          child: Container(
                            margin: EdgeInsets.only(left: 10.w),
                            width: 74.w,
                            height: 38.h,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              color: Color(0xFF007BE5),
                              borderRadius: BorderRadius.circular(4.r),
                            ),
                            child: Obx(() =>
                            Text(
                              controller.timeTip.value,
                              style:
                              TextStyle(color: Colors.white, fontSize: 11.sp),
                            ),
                          ))
                        )
                  ,
                      ],
                    ),
                    SizedBox(
                      height: 12.h,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          '原密码：',
                          style: TextStyle(
                              color: Color(0xFF333333), fontSize: 14.sp),
                        ),
                        Container(
                            height: 38.h,
                            width: 230.w,
                            decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(4.r),
                                border: Border.all(
                                    width: 1.w, color: Color(0xFFE4E4E4))),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Container(
                                    height: 38.h,
                                    width: 150.w,
                                    child: AccountEdit2Text(
                                      //获取返回的输入内容
                                      hitText: '请输入',
                                      icon: '',
                                      contentStrCallBack: (content) {
                                        controller.psw = content;
                                      },
                                      key: ValueKey('phone'),
                                    )),
                                // Container(
                                //   margin: EdgeInsets.only(right: 16.w),
                                //   child: Image.asset(
                                //     '${Constant.IMG_BASE}eye_close.png',
                                //     width: 17.w,
                                //     height: 11.h,
                                //   ),
                                // )
                              ],
                            ))
                      ],
                    ),
                    SizedBox(
                      height: 12.h,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          '新密码：',
                          style: TextStyle(
                              color: Color(0xFF333333), fontSize: 14.sp),
                        ),
                        Container(
                            height: 38.h,
                            width: 230.w,
                            decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(4.r),
                                border: Border.all(
                                    width: 1.w, color: Color(0xFFE4E4E4))),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Container(
                                    height: 38.h,
                                    width: 150.w,
                                    child: AccountEdit2Text(
                                      //获取返回的输入内容
                                      hitText: '请输入',
                                      icon: '',
                                      contentStrCallBack: (content) {
                                        controller.psw2 = content;
                                      },
                                      key: ValueKey('phone'),
                                    )),
                                // Container(
                                //   margin: EdgeInsets.only(right: 16.w),
                                //   child: Image.asset(
                                //     '${Constant.IMG_BASE}eye_open.png',
                                //     width: 17.w,
                                //     height: 11.h,
                                //   ),
                                // )
                              ],
                            ))
                      ],
                    ),
                    InkWell(
                        onTap: () {
                          controller._submit();
                        },
                        child: Container(
                          margin: EdgeInsets.only(top: 30.h),
                          height: 42.h,
                          width: MediaQuery.of(context).size.width - 64.w,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              color: Color(0xFF007BE5),
                              borderRadius: BorderRadius.circular(8.r)),
                          child: Text(
                            '确定',
                            style:
                                TextStyle(fontSize: 14.sp, color: Colors.white),
                          ),
                        ))
                  ],
                ),
              ),
            ),
          ]),
        ));
      },
    );
  }

  Future<Future<int?>> _showSingle(title) async {
    return showModalBottomSheet<int>(
        backgroundColor: Colors.transparent,
        isScrollControlled: true,
        context: context,
        builder: (BuildContext context1) {
            return AnimatedPadding(
                padding: MediaQuery.of(context1).viewInsets, // 我们可以根据这个获取需要的padding
                duration: const Duration(milliseconds: 100),
              child:  Container(
                  height: 200.h,
                  clipBehavior: Clip.antiAlias,
                  decoration: const BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(20.0),
                      topRight: Radius.circular(20.0),
                    ),
                  ),
                  child: Column(
                    children: [
                      SizedBox(height: 15.h,),
                      Text('输入'+title,style: TextStyle(
                          fontSize: 15.sp
                      ),),
                      Container(
                        margin: EdgeInsets.all(10.w),
                        decoration: BoxDecoration(
                            border: Border.all(color: Color(0xFFE4E4E4),width: 1.w)
                        ),
                        child:
                          AccountEdit2Text(key: const ValueKey('title'),hitText: '请输入'+title, contentStrCallBack: (value){
                            controller.updateStr = value;
                          })

                      ),
                      InkWell(
                          onTap: (){
                            if(title=='电话'){
                              print('11111==='+controller.updateStr.toString());
                              if( !RegExpUtils.isPhoneNumber(controller.updateStr)){
                                ToastUtil.show('请输入正确手机号');
                                return;
                              }
                            }
                            if(title=='QQ'){
                              if( !RegExpUtils.isQQ(controller.updateStr)){
                                ToastUtil.show('请输入正确QQ号码');
                                return;
                              }
                            }

                            controller._updateUser(title,);
                            Navigator.pop(context1);

                          },
                          child:  Container(
                            height: 40.h,
                            margin: EdgeInsets.all(10.w),
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(8.r),
                                color: const Color(0xFF007BE5)
                            ),
                            child: Text('确定',style: TextStyle(
                                color: Colors.white,
                                fontSize: 13.sp
                            ),),
                          )
                      )

                    ],
                  )
              )
            ) ;
        });
  }

  Future<Future<int?>> _showDeleteAccount() async {
    return showModalBottomSheet<int>(
      backgroundColor: Colors.transparent,
      isScrollControlled: true,
      context: context,
      builder: (BuildContext context) {
        return  AnimatedPadding(
            padding: MediaQuery.of(context).viewInsets, // 我们可以根据这个获取需要的padding
            duration: const Duration(milliseconds: 100),
            child: Container(
              clipBehavior: Clip.antiAlias,
              decoration: const BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(20.0),
                  topRight: Radius.circular(20.0),
                ),
              ),
              height: MediaQuery.of(context).size.height / 2.0,
              child: Column(children: [
                SizedBox(
                  height: 50,
                  child: Stack(
                    textDirection: TextDirection.rtl,
                    children: [
                      const Center(
                        child: Text(
                          '注销账号',
                          style: TextStyle(
                            fontSize: 15,
                            color: Color(0xFF333333),
                          ),
                        ),
                      ),
                      IconButton(
                          icon: Icon(Icons.close),
                          onPressed: () {
                            Navigator.of(context).pop();
                            if( controller._timer!=null){
                              controller._timer?.cancel();
                            }

                          }),
                    ],
                  ),
                ),
                Expanded(
                  child: Container(
                    width: MediaQuery.of(context).size.width,
                    alignment: Alignment.center,
                    child: Column(
                      children: [
                        SizedBox(
                          height: 12.h,
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text(
                              '手机号：',
                              style: TextStyle(
                                  color: Color(0xFF333333), fontSize: 14.sp),
                            ),
                            Container(
                              height: 38.h,
                              width: 230.w,
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(4.r),
                                  border: Border.all(
                                      width: 1.w, color: Color(0xFFE4E4E4))),
                              child: AccountEdit2Text(
                                onlyRead: true,
                                //获取返回的输入内容
                                hitText: '请输入',
                                defaultText: UserUtil.getUSER()!.mobile,
                                icon: '',
                                contentStrCallBack: (content) {
                                  controller.deletePhoneStr = content;
                                },
                                key: ValueKey('phone'),
                              ),
                            )
                          ],
                        ),
                        SizedBox(
                          height: 12.h,
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            SizedBox(
                              width: 10.w,
                            ),
                            Text(
                              '验证码：',
                              style: TextStyle(
                                  color: Color(0xFF333333), fontSize: 14.sp),
                            ),
                            Container(
                              height: 38.h,
                              width: 149.w,
                              alignment: Alignment.center,
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(4.r),
                                  border: Border.all(
                                      width: 1.w, color: Color(0xFFE4E4E4))),
                              child: AccountEdit2Text(
                                //获取返回的输入内容
                                hitText: '请输入',
                                icon: '',
                                contentStrCallBack: (content) {
                                  controller.deleteCodeStr= content;
                                },
                                key: ValueKey('newphone'),
                              ),
                            ),

                            InkWell(
                                onTap: (){
                                  controller._getCodeDelete('5');
                                  // controller._countTime();
                                },
                                child: Container(
                                    margin: EdgeInsets.only(left: 10.w),
                                    width: 74.w,
                                    height: 38.h,
                                    alignment: Alignment.center,
                                    decoration: BoxDecoration(
                                      color: Color(0xFF007BE5),
                                      borderRadius: BorderRadius.circular(4.r),
                                    ),
                                    child: Obx(() =>
                                        Text(
                                          controller.timeTip.value,
                                          style:
                                          TextStyle(color: Colors.white, fontSize: 11.sp),
                                        ),
                                    ))
                            )
                            ,
                          ],
                        ),
                        SizedBox(
                          height: 12.h,
                        ),
                        InkWell(
                            onTap: () {
                              if(controller.deletePhoneStr.isEmpty){
                                ToastUtil.show('请输入手机号');
                                return;
                              }
                              if(controller.deleteCodeStr.isEmpty){
                                ToastUtil.show('请输入验证码');
                                return;
                              }
                              controller._deleteUser();
                            },
                            child: Container(
                              margin: EdgeInsets.only(top: 30.h),
                              height: 42.h,
                              width: MediaQuery.of(context).size.width - 64.w,
                              alignment: Alignment.center,
                              decoration: BoxDecoration(
                                  color: Color(0xFF007BE5),
                                  borderRadius: BorderRadius.circular(8.r)),
                              child: Text(
                                '确定',
                                style:
                                TextStyle(fontSize: 14.sp, color: Colors.white),
                              ),
                            ))
                      ],
                    ),
                  ),
                ),
              ]),
            ));
      },
    );
  }

  _showDelte(){
    showDialog(context: context, builder: (BuildContext context1) {
      return MySimpleDialog(callBack: (String content) {
        if(content == 'cancel'){
          Navigator.pop(context1);
        }else if(content == 'sure'){
          Navigator.pop(context1);
          _showDeleteAccount();
        }
      },
        title: '注销账号',
        msg: '您确定要注销吗？',
        sureText: '确定',
      );
    },
    );
  }




}
